#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 1001
#define inf 0x3fffffff
int n, x;
int lose[maxn], win[maxn], use[maxn];
long f[maxn][maxn];
int main()
{
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
    {
        cin >> lose[i] >> win[i] >> use[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j <= x; ++j)
        {
            if (j >= use[i])
                f[i][j] = max(f[i - 1][j] + lose[i], f[i - 1][j - use[i]] + win[i]);
            else
                f[i][j] = f[i - 1][j] + lose[i];
        }
    }
    cout << 5 * f[n][x] << endl;
    return 0;
}